package com.yonyou.pmclouds.enterprise.process;

import com.yonyou.pmclouds.basecom.bp.processor.MultiProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.enterprise.entity.EnterpriseVO;
import com.yonyou.pmclouds.personnel.entity.PersonnelVO;
import com.yonyou.pmclouds.personnel.rmiitf.PersonnelMaintain;
import com.yonyou.pmclouds.personnel.rmiitf.PersonnelQuery;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashSet;

/**
 * @Author chulf
 * @Date 2020/4/17
 * @Description
 **/
@Component
public class DeletePersonAfterProcess implements MultiProcessor<EnterpriseVO> {

    @Autowired
    private PersonnelQuery personnelQuery;
    @Autowired
    private PersonnelMaintain personnelMaintain;

    @Override
    public void process(EnterpriseVO[] vos, EnterpriseVO[] origs) throws BusinessException {

        HashSet<String> pkEtps = new HashSet<>();
        for (EnterpriseVO vo : vos) {
            pkEtps.add(vo.getPkEnterprise());
        }

        //删除对应企业下的人员
        PersonnelVO[] personnelVOS = personnelQuery.queryPersonnelsByPkEtps(pkEtps.toArray(new String[0]));

        if (ArrayUtils.isEmpty(personnelVOS)) return;
        for (PersonnelVO personnelVO : personnelVOS) {
            personnelVO.setDr((byte)1);
        }

        personnelMaintain.savePersonnels(personnelVOS);
    }
}
